package com.lyz.collectionDemo.arrayList;

import java.util.ArrayList;

/**
 * @ClassName ArrayListDemo3
 * @Description 集合存储自定义元素并遍历
 * @Author 2214361854
 * @Date 2022/2/16 23:24
 * @Version 1.0
 */
public class ArrayListDemo3 {
    public static void main(String[] args) {
        //创建ArrayList,泛型 Movie(自定义类) ,片名 评分 演员
        ArrayList<Movie> movies = new ArrayList<Movie>(){{
            add(new Movie("《肖申克》",9.7,"罗宾斯"));
            add(new Movie("《霸王别姬》",9.6,"张国荣"));
            add(new Movie("《阿甘》",9.5,"汉克斯"));
        }};
        System.out.println(movies);

        for (int i = 0; i < movies.size(); i++) {
            Movie movie = movies.get(i);
            System.out.println(movie.toString());
        }
    }
}
